package com.sunfeng.chap2.p17;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;

/**
 * @Author : 孙峰
 * @Description: overlaps  判断次锁定是否与给定锁定区域重叠
 * @Date : 2021/10/11  9:41
 */
public class FileLockAPI_2 {
    public static void main(String[] args) throws IOException {
        File file = new File("d:\\nio\\a.txt");
        RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
        FileChannel fileChannel = randomAccessFile.getChannel();

        FileLock lock = fileChannel.lock(1, 10, true);
        System.out.println(lock.overlaps(5,10));  // true
        lock.close();
    }
}
